Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-swap non-osmo tx fees to osmo #1145

Merged
merged 84 commits into from
Apr 22, 2022
Merged

Auto-swap non-osmo tx fees to osmo #1145

merged 84 commits into from
Apr 22, 2022

Conversation

AlpinYukseloglu
Copy link
Contributor

@AlpinYukseloglu AlpinYukseloglu commented Mar 25, 2022

Closes: #1121

Description

  • Moved DeductFeeDecorator from auth -> txfees module
  • Created second module account in txfees module to receive non-OSMO tx fees
  • Implemented logic to route non-OSMO fees to second module account
  • Set up AfterEpochEnd listener to trigger fee swaps into base denom + transfer to the main module account
  • Did all the necessary wiring in app & txfees module (hook-related + misc.)
  • Set up testing for all major changes/additions (primarily in feedecorator_test.go and hooks_test.go)

For contributor use:

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

@codecov-commenter
Copy link

codecov-commenter commented Mar 25, 2022

Codecov Report

Merging #1145 (f341152) into main (0b3e383) will decrease coverage by 0.73%.
The diff coverage is 60.00%.

@@            Coverage Diff             @@
##             main    #1145      +/-   ##
==========================================
- Coverage   20.26%   19.53%   -0.74%     
==========================================
  Files         203      200       -3     
  Lines       26824    27532     +708     
==========================================
- Hits         5436     5377      -59     
- Misses      20378    21153     +775     
+ Partials     1010     1002       -8     
Impacted Files Coverage Δ
x/txfees/keeper/feedecorator.go 60.82% <46.93%> (-14.18%) ⬇️
x/txfees/keeper/hooks.go 72.72% <72.72%> (ø)
x/txfees/keeper/keeper.go 92.85% <100.00%> (+5.35%) ⬆️
x/claim/genesis.go
x/claim/keeper/grpc_query.go
x/claim/handler.go
x/claim/client/cli/tx.go
x/claim/keeper/params.go
x/claim/module.go
x/claim/keeper/claim.go
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0b3e383...f341152. Read the comment docs.

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Just left some initial minor feedback

app/ante.go Show resolved Hide resolved
app/ante.go Outdated Show resolved Hide resolved
x/txfees/keeper/feedecorator.go Outdated Show resolved Hide resolved
x/txfees/keeper/feedecorator.go Outdated Show resolved Hide resolved
x/txfees/keeper/feedecorator.go Outdated Show resolved Hide resolved
x/txfees/keeper/feedecorator.go Outdated Show resolved Hide resolved
x/txfees/keeper/feedecorator.go Outdated Show resolved Hide resolved
x/txfees/keeper/feedecorator.go Outdated Show resolved Hide resolved
x/txfees/keeper/feedecorator.go Outdated Show resolved Hide resolved
x/txfees/keeper/feedecorator.go Outdated Show resolved Hide resolved
app/keepers.go Outdated Show resolved Hide resolved
app/keepers.go Outdated Show resolved Hide resolved
app/apptesting/test_suite.go Show resolved Hide resolved
app/keepers.go Show resolved Hide resolved
x/txfees/keeper/feedecorator.go Outdated Show resolved Hide resolved
x/txfees/keeper/feedecorator.go Show resolved Hide resolved
x/txfees/keeper/feedecorator_test.go Outdated Show resolved Hide resolved
x/txfees/keeper/feedecorator_test.go Outdated Show resolved Hide resolved
x/txfees/keeper/hooks.go Outdated Show resolved Hide resolved
x/txfees/keeper/hooks.go Show resolved Hide resolved
x/txfees/keeper/hooks.go Show resolved Hide resolved
@alexanderbez
Copy link
Contributor

@mattverse wanna give this one more look?

Copy link
Member

@mattverse mattverse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some minor comments!

Also, would it be possible to add documnetation in spec before we merge this?

x/txfees/types/expected_keepers.go Show resolved Hide resolved

func NewKeeper(
cdc codec.Codec,
accountKeeper types.AccountKeeper,
bankKeeper *bankkeeper.BaseKeeper,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reminder: Should use bank keeper from expected_keepers, instead of using it in a direct import form!

Comment on lines +41 to +61
coins := sdk.NewCoins(sdk.NewInt64Coin(uion, 10),
sdk.NewInt64Coin(atom, 20),
sdk.NewInt64Coin(ust, 14))

swapFee := sdk.NewDec(0)

expectedOutput1, err := uionPool.CalcOutAmtGivenIn(suite.Ctx,
sdk.Coins{sdk.Coin{Denom: uion, Amount: coins.AmountOf(uion)}},
baseDenom,
swapFee)
suite.Require().NoError(err)
expectedOutput2, err := atomPool.CalcOutAmtGivenIn(suite.Ctx,
sdk.Coins{sdk.Coin{Denom: atom, Amount: coins.AmountOf(atom)}},
baseDenom,
swapFee)
suite.Require().NoError(err)
expectedOutput3, err := ustPool.CalcOutAmtGivenIn(suite.Ctx,
sdk.Coins{sdk.Coin{Denom: ust, Amount: coins.AmountOf(ust)}},
baseDenom,
swapFee)
suite.Require().NoError(err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would it be possible to change these to foo, bar, baz? I personally don't prefer using token names directly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think this is better than foo bar baz

suite.App.EpochsKeeper.AfterEpochEnd(futureCtx, params.DistrEpochIdentifier, int64(1))

suite.Require().Empty(suite.App.BankKeeper.GetAllBalances(suite.Ctx, moduleAddrNonNativeFee))
suite.Require().True(suite.App.BankKeeper.GetBalance(suite.Ctx, moduleAddrFee, baseDenom).Amount.GTE(fullExpectedOutput.Amount.TruncateInt()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to testing w/ precise number instead of using GTE?

x/txfees/keeper/feedecorator.go Outdated Show resolved Hide resolved
x/txfees/keeper/feedecorator.go Outdated Show resolved Hide resolved
x/txfees/keeper/feedecorator_test.go Outdated Show resolved Hide resolved
@ValarDragon
Copy link
Member

Because this is a legacy PR thats been open so long, I'm in favor of merging it, and doing spec updates in a second issue/PR,

Right now theres not really a well formatted spec for this module to begin with, and I don't think its worth blocking the merge which has several useful updates, and will keep getting merge conflicts, until the spec is done

@danwt
Copy link

danwt commented Oct 17, 2024

Hiya, I was just curious what is the benefit of doing this in epoch as opposed to on the fly? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Auto-swap non-osmo tx fees to osmo
7 participants